Skip to content

Model Config: DB-driven validator, seed sarvamai/elevenlabs/google#859

Open
vprashrex wants to merge 12 commits into
mainfrom
chore/model-config-evals
Open

Model Config: DB-driven validator, seed sarvamai/elevenlabs/google#859
vprashrex wants to merge 12 commits into
mainfrom
chore/model-config-evals

Conversation

@vprashrex
Copy link
Copy Markdown
Collaborator

@vprashrex vprashrex commented May 18, 2026

Target issue is: #693

Summary

Previously, config/version creation accepted any completion.params.model without validating it against model_config, allowing unsupported or misspelled models to fail only at inference time. STT/TTS providers and models for Google, Sarvamai, and ElevenLabs were also missing from model_config.

This update adds model validation during config/version creation, seeds missing STT/TTS provider configs, and centralizes provider/model validation within the CRUD layer.

What changed:

  • validate_blob_model_or_raise in crud/model_config.py — validates provider,
    model, completion type, and TTS voice; wired into all job/config entry points
  • Hardcoded SUPPORTED_MODELS / SUPPORTED_VOICES dicts removed; model_config
    is now the single source of truth
  • Migration 063: completion_type column, 4 indexes (composite + GIN), 10 new
    STT/TTS rows seeded with pricing for Google models

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

Adds two Alembic migrations (indexes and seeded STT/TTS model configs), expands ModelConfig provider/completion types and indexes, removes static model/voice whitelists, implements DB-backed blob model/voice validation, integrates validation into config CRUD and job flows, and updates tests accordingly.

Changes

Model Provider Expansion and Database-Driven Validation

Layer / File(s) Summary
Migrations, seeds, and provider schema
backend/app/alembic/versions/062_add_pending_job_monitoring_indexes.py, backend/app/alembic/versions/063_seed_stt_tts_model_configs.py
Adds migration 062 (concurrent pending-job monitoring indexes) and migration 063 (provider/completion enums, completion_type column, backfill, indexes, and seeded model rows).
ModelConfig schema and indexes
backend/app/models/model_config.py
Expands ModelConfigBase.provider to include sarvamai and elevenlabs, adds CompletionType and completion_type enum-backed column, and appends provider/completion/modality indexes.
ModelConfig CRUD: types and helpers
backend/app/crud/model_config.py
Adds Provider alias, _normalize_provider, widens provider parameters, and adds list_supported_models / is_model_supported helper queries.
Blob model validation implementation
backend/app/crud/model_config.py
Adds validate_blob_model_or_raise() to require model for non-native providers, verify model existence and completion_type support, and validate TTS voice options; raises HTTP 400 on failures.
Config CRUD integration
backend/app/crud/config/config.py, backend/app/crud/config/version.py
Calls validate_blob_model_or_raise in create_or_raise flows to validate inline/stored config blobs before persisting configs and versions.
Remove static model and voice whitelists
backend/app/models/llm/constants.py, backend/app/models/llm/request.py
Removes SUPPORTED_MODELS and SUPPORTED_VOICES; simplifies KaapiCompletionConfig.validate_params to stop enforcing whitelist checks and auto-default provider for stt/tts.
Job execution integration
backend/app/services/llm/jobs.py
Validates inline and stored config blobs during start_job/start_chain_job/resolve_config_blob/execute_llm_call; converts validation failures into structured job errors.
Unit tests and test updates
backend/app/tests/crud/test_model_config.py, backend/app/tests/api/routes/configs/test_version.py, backend/app/tests/models/llm/test_request.py
Adds tests for validate_blob_model_or_raise, updates config/version tests to assert type-change constraints and provider defaults, and removes obsolete whitelist-based tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • AkhileshNegi
  • Prajna1999
  • kartpop

"I hopped through migrations, seeds, and code,
I swapped whitelists for DB truth on the road,
Providers grew tall, voices learned their name,
Configs now validated before jobs take aim,
Cheers from the rabbit — tests pass, all in the load!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.90% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: introducing a DB-driven validator for model configs and seeding configurations for three new providers (sarvamai, elevenlabs, google).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/model-config-evals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 95.60440% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/services/llm/jobs.py 70.58% 5 Missing ⚠️
backend/app/crud/model_config.py 94.59% 2 Missing ⚠️
backend/app/tests/crud/test_model_config.py 98.75% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@vprashrex vprashrex self-assigned this May 20, 2026
@vprashrex vprashrex added the bug Something isn't working label May 20, 2026
@vprashrex vprashrex linked an issue May 20, 2026 that may be closed by this pull request
@vprashrex vprashrex changed the title Model Config: Model Config: DB-driven validator, seed sarvamai/elevenlabs/google Model Config: DB-driven validator, seed sarvamai/elevenlabs/google May 20, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/app/models/llm/request.py (1)

265-282: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a return type annotation to validate_params.

The method at line 265 is missing a return type hint. Since it returns self (a KaapiCompletionConfig instance), add the return type annotation.

Proposed fix
-    def validate_params(self):
+    def validate_params(self) -> "KaapiCompletionConfig":

As per coding guidelines: **/*.py requires type hints on all function parameters and return values; Use Python 3.11+ with type hints throughout the codebase.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/models/llm/request.py` around lines 265 - 282, The method
validate_params currently lacks a return type annotation; update its signature
to annotate the return as the containing class (KaapiCompletionConfig) — i.e.,
change def validate_params(self) to def validate_params(self) ->
"KaapiCompletionConfig" (use a forward reference string if the class is defined
later or add from __future__ import annotations) so that callers know it returns
self; keep the implementation unchanged and ensure imports/annotations comply
with Python 3.11 typing rules.
🧹 Nitpick comments (4)
backend/app/tests/crud/test_model_config.py (1)

214-214: ⚡ Quick win

Remove unused monkeypatch fixture parameters in these tests.

Both functions currently trigger Ruff ARG001 and can be simplified safely.

♻️ Proposed fix
-def test_validate_blob_none_provider_skips(monkeypatch: pytest.MonkeyPatch) -> None:
+def test_validate_blob_none_provider_skips() -> None:
@@
-def test_validate_blob_missing_model_raises(monkeypatch: pytest.MonkeyPatch) -> None:
+def test_validate_blob_missing_model_raises() -> None:

Also applies to: 220-220

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/tests/crud/test_model_config.py` at line 214, The two tests
test_validate_blob_none_provider_skips and the other test at the nearby block
currently accept an unused monkeypatch fixture causing Ruff ARG001; remove the
unused monkeypatch parameter from their function signatures (e.g., change def
test_validate_blob_none_provider_skips(monkeypatch: pytest.MonkeyPatch) -> None:
to def test_validate_blob_none_provider_skips() -> None:) and run tests to
ensure no remaining references to monkeypatch exist.
backend/app/alembic/versions/063_seed_stt_tts_model_configs.py (1)

32-67: ⚡ Quick win

Add return type hints for upgrade and downgrade.

Please annotate both functions with -> None for consistency with the project typing rule.

As per coding guidelines: "**/*.py: Always add type hints to all function parameters and return values in Python code".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py` around lines
32 - 67, The upgrade and downgrade functions lack return type annotations; add
"-> None" to both function definitions (upgrade and downgrade) so their
signatures read with a None return type, keeping the bodies unchanged and
conforming to the project's typing rule for Python functions.
backend/app/alembic/versions/062_add_pending_job_monitoring_indexes.py (1)

35-56: ⚡ Quick win

Add explicit return type hints to migration functions.

upgrade/downgrade should be annotated as -> None to match repo typing standards.

As per coding guidelines: "**/*.py: Always add type hints to all function parameters and return values in Python code".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/alembic/versions/062_add_pending_job_monitoring_indexes.py`
around lines 35 - 56, Annotate the migration entry points with explicit return
type hints: change the function signatures of upgrade and downgrade to include
-> None (i.e., def upgrade() -> None: and def downgrade() -> None:) so they
match the repository typing standards and satisfy the rule to add return type
hints for all functions like the ones that call
op.get_context().autocommit_block() and op.create_index/op.drop_index.
backend/app/crud/model_config.py (1)

66-87: ⚡ Quick win

Type-annotate _modality_filter signature.

stmt and return type are currently implicit. Add explicit types (e.g., Select-based typing) to satisfy repo-wide typing requirements.

As per coding guidelines: "**/*.py: Always add type hints to all function parameters and return values in Python code".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/crud/model_config.py` around lines 66 - 87, Update the
_modality_filter signature to add explicit SQLAlchemy Select typing: change def
_modality_filter(stmt, completion_type: CompletionType): to def
_modality_filter(stmt: Select, completion_type: CompletionType) -> Select: and
add the appropriate import for Select (e.g. from sqlalchemy.sql import Select or
from sqlalchemy.sql.selectable import Select) at the top of the module; keep all
existing logic using ModelConfig, ARRAY, and sqltypes.String unchanged so the
function still returns the filtered Select object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py`:
- Around line 66-83: The current downgrade() uses op.execute(...) to
unconditionally DELETE rows matching provider/model_name which may remove
pre-existing data; either make downgrade() a no-op or modify both upgrade() and
downgrade(): in upgrade() (the INSERT ... ON CONFLICT ... DO NOTHING block) add
a deterministic marker (e.g., set a seeded_by or migration_tag column or INSERT
and capture RETURNING id into a temp table) so you can identify which rows this
revision actually created, and then change downgrade() to only DELETE rows that
match those inserted records (matching the marker or the captured ids) rather
than deleting by provider/model_name alone.

In `@backend/app/crud/model_config.py`:
- Around line 119-132: The docstring for the validation block is inconsistent
with the code: it says native configs must include completion.params.model but
the function returns early for raw_provider.endswith("-native") (see
blob.completion, raw_provider, completion_type) and thus skips that validation;
fix by making them consistent—either remove the early return and enforce the
model presence for all providers (delete the raw_provider.endswith("-native")
return and validate completion.params.model against model_config) or update the
docstring to explicitly state that native providers
(raw_provider.endswith("-native")) are exempt from the model requirement so
callers know native-provider behavior is allowed to omit
completion.params.model.

In `@backend/app/tests/crud/test_model_config.py`:
- Around line 166-168: Add explicit type hints for the helper functions:
annotate _make_blob parameters (e.g., provider: str, completion_type: str,
params: Mapping[str, Any]) and its return type (e.g., SimpleNamespace) and do
the same for the inner function boom (declare its parameters and return type).
Also rename boom's varargs to underscored names (e.g., _args, _kwargs) to
silence unused-arg lint warnings. Apply the same parameter/return annotation
updates to the other helper on lines ~201-203 as well.

---

Outside diff comments:
In `@backend/app/models/llm/request.py`:
- Around line 265-282: The method validate_params currently lacks a return type
annotation; update its signature to annotate the return as the containing class
(KaapiCompletionConfig) — i.e., change def validate_params(self) to def
validate_params(self) -> "KaapiCompletionConfig" (use a forward reference string
if the class is defined later or add from __future__ import annotations) so that
callers know it returns self; keep the implementation unchanged and ensure
imports/annotations comply with Python 3.11 typing rules.

---

Nitpick comments:
In `@backend/app/alembic/versions/062_add_pending_job_monitoring_indexes.py`:
- Around line 35-56: Annotate the migration entry points with explicit return
type hints: change the function signatures of upgrade and downgrade to include
-> None (i.e., def upgrade() -> None: and def downgrade() -> None:) so they
match the repository typing standards and satisfy the rule to add return type
hints for all functions like the ones that call
op.get_context().autocommit_block() and op.create_index/op.drop_index.

In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py`:
- Around line 32-67: The upgrade and downgrade functions lack return type
annotations; add "-> None" to both function definitions (upgrade and downgrade)
so their signatures read with a None return type, keeping the bodies unchanged
and conforming to the project's typing rule for Python functions.

In `@backend/app/crud/model_config.py`:
- Around line 66-87: Update the _modality_filter signature to add explicit
SQLAlchemy Select typing: change def _modality_filter(stmt, completion_type:
CompletionType): to def _modality_filter(stmt: Select, completion_type:
CompletionType) -> Select: and add the appropriate import for Select (e.g. from
sqlalchemy.sql import Select or from sqlalchemy.sql.selectable import Select) at
the top of the module; keep all existing logic using ModelConfig, ARRAY, and
sqltypes.String unchanged so the function still returns the filtered Select
object.

In `@backend/app/tests/crud/test_model_config.py`:
- Line 214: The two tests test_validate_blob_none_provider_skips and the other
test at the nearby block currently accept an unused monkeypatch fixture causing
Ruff ARG001; remove the unused monkeypatch parameter from their function
signatures (e.g., change def test_validate_blob_none_provider_skips(monkeypatch:
pytest.MonkeyPatch) -> None: to def test_validate_blob_none_provider_skips() ->
None:) and run tests to ensure no remaining references to monkeypatch exist.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: adea4ba3-9ad8-449f-9bb1-55caa06b92ef

📥 Commits

Reviewing files that changed from the base of the PR and between 68369a8 and 4be5b8c.

📒 Files selected for processing (11)
  • backend/app/alembic/versions/062_add_pending_job_monitoring_indexes.py
  • backend/app/alembic/versions/063_seed_stt_tts_model_configs.py
  • backend/app/crud/config/config.py
  • backend/app/crud/config/version.py
  • backend/app/crud/model_config.py
  • backend/app/models/llm/constants.py
  • backend/app/models/llm/request.py
  • backend/app/models/model_config.py
  • backend/app/tests/api/routes/configs/test_version.py
  • backend/app/tests/crud/test_model_config.py
  • backend/app/tests/models/llm/test_request.py
💤 Files with no reviewable changes (3)
  • backend/app/tests/api/routes/configs/test_version.py
  • backend/app/tests/models/llm/test_request.py
  • backend/app/models/llm/constants.py

Comment thread backend/app/alembic/versions/063_seed_stt_tts_model_configs.py
Comment thread backend/app/crud/model_config.py
Comment thread backend/app/tests/crud/test_model_config.py Outdated
Comment thread backend/app/crud/model_config.py Outdated
return session.exec(stmt).first() is not None


def validate_blob_model_or_raise(session: Session, blob: Any) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline-blob path on /llm/call and /llm/chain no longer validates model/voice. Before this PR, model/voice checks lived in KaapiCompletionConfig.validate_params, so FastAPI ran them on every request body that contained a ConfigBlob — including ad-hoc inline blobs sent to /llm/call. This PR moves the check into validate_blob_model_or_raise (which needs a DB session) and only wires it into ConfigCrud.create_or_raise and ConfigVersionCrud.create_or_raise. The inline-blob branch in services/llm/jobs.py:525 (config_blob = config.blob) never calls it, so a client can now POST {"provider": "google", "type": "tts", "params": {"model": "gemini-99-ultra", "voice": "Nonexistent"}} and the request will be accepted, a job row created, and the failure surfaces deep in the worker instead of as a 4xx at request time

assert data["data"]["version"]["config_blob"]["completion"]["type"] == "text"


def test_create_version_with_kaapi_stt_provider_success(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add these coverage testcases as well
- test_create_version_cannot_change_type_from_stt_to_tts — start with a google + gemini-2.5-pro STT config, try to bump it to google + gemini-2.5-flash-preview-tts TTS, expect 400 immutability error.
- test_create_version_cannot_change_type_from_tts_to_text — start with a google + gemini-2.5-flash-preview-tts TTS config, try to bump it to openai + gpt-4o text, expect 400 immutability error.
- test_create_version_with_kaapi_stt_provider_success — create a google + gemini-2.5-pro STT config, post a new version that just tweaks instructions/temperature, expect 201 with version == 2 and type == "stt".
- test_create_version_with_kaapi_tts_provider_success — create a google + gemini-2.5-flash-preview-tts (voice Kore) TTS config, post a new version switching to e.g. gemini-2.5-pro-preview-tts with a different seeded voice, expect 201 with version == 2 and type == "tts".

DEFAULT_TTS_VOICE,
SUPPORTED_MODELS,
SUPPORTED_VOICES,
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we need to add check that STT/TTS is not supported for OpenAI and send appropriate error message

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in model config there is already an column for input and output modalities which is set .. that has AUDIO, TEXT AND IMAGE ... from that TTS/STT capabilities can be checked

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
"success": false,
"data": null,
"error": "Provider 'openai' does not support completion type='tts'.",
"errors": null,
"metadata": null
}

@vprashrex vprashrex requested a review from AkhileshNegi May 22, 2026 06:30
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
backend/app/alembic/versions/063_seed_stt_tts_model_configs.py (1)

32-32: ⚡ Quick win

Add return annotations to the Alembic hooks.

upgrade() and downgrade() are new Python functions without return type hints, which breaks the repo-wide typing rule.

Proposed fix
-def upgrade():
+def upgrade() -> None:
@@
-def downgrade():
+def downgrade() -> None:

As per coding guidelines, **/*.py: Always add type hints to all function parameters and return values in Python code.

Also applies to: 132-132

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py` at line 32,
The Alembic hook functions upgrade() and downgrade() are missing return type
annotations; add explicit return type hints (e.g., def upgrade() -> None: and
def downgrade() -> None:) to both functions in this migration module so they
conform to the repo-wide typing rule and satisfy static type checks; update the
function signatures where upgrade and downgrade are defined (including the
duplicate at lines noted) to include the -> None return annotation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py`:
- Around line 138-147: The downgrade currently drops the new enum types and
column but leaves rows with providers introduced in this revision, which will
break older code; update the downgrade() in this migration (the function
containing the op.execute calls) to either delete rows with provider IN
('sarvamai','elevenlabs') from global.model_config before reverting the
column/type changes or explicitly raise a RuntimeError/sa_exc to mark the
revision as irreversible; if choosing deletion, run an op.execute("DELETE FROM
global.model_config WHERE provider IN ('sarvamai','elevenlabs')") prior to
dropping/altering the provider enum and column so the pre-063 app can read the
table.

In `@backend/app/crud/model_config.py`:
- Around line 69-74: The query building up stmt using
select(ModelConfig.model_name).where(... ) returns rows in arbitrary DB order;
add an explicit ordering to the statement (e.g., order by ModelConfig.model_name
ascending) before calling session.exec(stmt).all() so the returned list is
deterministic; update the stmt construction that references
select(ModelConfig.model_name), ModelConfig.provider,
ModelConfig.completion_type and ModelConfig.is_active to include an
order_by(...) clause.

---

Nitpick comments:
In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py`:
- Line 32: The Alembic hook functions upgrade() and downgrade() are missing
return type annotations; add explicit return type hints (e.g., def upgrade() ->
None: and def downgrade() -> None:) to both functions in this migration module
so they conform to the repo-wide typing rule and satisfy static type checks;
update the function signatures where upgrade and downgrade are defined
(including the duplicate at lines noted) to include the -> None return
annotation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd1e5f14-5a26-4005-b9aa-0aee8138b963

📥 Commits

Reviewing files that changed from the base of the PR and between 45e6b6a and e0f63d4.

📒 Files selected for processing (4)
  • backend/app/alembic/versions/063_seed_stt_tts_model_configs.py
  • backend/app/crud/model_config.py
  • backend/app/models/model_config.py
  • backend/app/tests/crud/test_model_config.py

Comment on lines +138 to +147
op.execute(
"""
ALTER TABLE global.model_config
DROP COLUMN completion_type,
ALTER COLUMN provider TYPE varchar USING provider::varchar
"""
)

op.execute("DROP TYPE IF EXISTS global.completion_type_enum")
op.execute("DROP TYPE IF EXISTS global.provider_enum")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Rollback still leaves post-063 providers behind.

downgrade() removes the enum/column changes, but it keeps the sarvamai and elevenlabs rows introduced by this revision. Pre-063 code only handled openai/google, so a rollback can still leave global.model_config unreadable to the older app layer. Either clean up providers introduced here during downgrade or mark the migration as intentionally irreversible.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/alembic/versions/063_seed_stt_tts_model_configs.py` around lines
138 - 147, The downgrade currently drops the new enum types and column but
leaves rows with providers introduced in this revision, which will break older
code; update the downgrade() in this migration (the function containing the
op.execute calls) to either delete rows with provider IN
('sarvamai','elevenlabs') from global.model_config before reverting the
column/type changes or explicitly raise a RuntimeError/sa_exc to mark the
revision as irreversible; if choosing deletion, run an op.execute("DELETE FROM
global.model_config WHERE provider IN ('sarvamai','elevenlabs')") prior to
dropping/altering the provider enum and column so the pre-063 app can read the
table.

Comment on lines +69 to +74
stmt = select(ModelConfig.model_name).where(
ModelConfig.provider == provider,
ModelConfig.completion_type == completion_type,
ModelConfig.is_active,
)
return list(session.exec(stmt).all())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Order the supported-model list before surfacing it.

This list is returned directly in the 400 detail on Lines 141-144. Without an ORDER BY, PostgreSQL can return models in different orders, which makes the API payload and any assertions against it flaky.

Proposed fix
     stmt = select(ModelConfig.model_name).where(
         ModelConfig.provider == provider,
         ModelConfig.completion_type == completion_type,
         ModelConfig.is_active,
     )
+    stmt = stmt.order_by(ModelConfig.model_name)
     return list(session.exec(stmt).all())
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/crud/model_config.py` around lines 69 - 74, The query building up
stmt using select(ModelConfig.model_name).where(... ) returns rows in arbitrary
DB order; add an explicit ordering to the statement (e.g., order by
ModelConfig.model_name ascending) before calling session.exec(stmt).all() so the
returned list is deterministic; update the stmt construction that references
select(ModelConfig.model_name), ModelConfig.provider,
ModelConfig.completion_type and ModelConfig.is_active to include an
order_by(...) clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluation: Clear error message

3 participants